package com.wsn.smarthouse;

import java.net.DatagramSocket;

import android.os.Handler;
//import android.os.Looper;
import android.os.Message;
import android.util.Log;

public class AliveThread extends Thread {
	private DatagramSocket ds;
	private final static String logtag= "AliveThread";
	private static String nodewatched = "Event Watch ";
	
	public static Handler alivehandler=new Handler(){
		@Override
		public void handleMessage(Message msg){
			super.handleMessage(msg);
			Log.v(logtag,(String)msg.obj);
			String rec = (String)msg.obj;
			if(rec.startsWith("watch")){
				String[] onelineSet = rec.split(" ");
				nodewatched = nodewatched+onelineSet[1]+" ";
			}
		}
	};
	
	public AliveThread (DatagramSocket ds){
		this.ds=ds;
	}
	
	@Override
	public void run(){
		while(true){
			String cmd = "Get Info/NodeSensorView/*/Query?nodename!=''";
			Log.v(logtag,""+cmd);
			NetSend netsend = new NetSend(ds,cmd);
			netsend.start();
			try{
				Thread.sleep(5000);
			}catch(InterruptedException e){
				
			}
		}
	}
	

}
